package com.kws.merchant.controller;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.kws.common.redis.service.RedisService;
import com.kws.common.security.auth.AuthUtil;
import com.kws.common.security.utils.SecurityUtils;
import com.kws.merchant.domain.Merchant;
import com.kws.merchant.domain.po.*;
import com.kws.merchant.domain.vo.*;
import com.kws.merchant.service.MerchantService;
import com.kws.system.api.domain.SysUser;
import com.kws.system.api.enumDo.RedisConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;

import java.util.LinkedList;
import java.util.List;

/**
 * (Merchant)表控制层
 *
 * @author yxy
 * @since 2024-11-01 09:43:20
 */
@RestController
@Api(tags = "商家")
@RequestMapping("merchant")
public class MerchantController {
    /**
     * 服务对象
     */
    @Resource
    private MerchantService merchantService;
    @Autowired
    private RedisService redisService;

    @ApiOperation("校验当前用户是否已注册企业")
    @GetMapping("/check/loginCompany")
    public R checkLoginCompany(){
        Long userId = SecurityUtils.getUserId();
        boolean status = merchantService.checkLoginCompany(userId);
        return R.ok(status);
    }

    @ApiOperation("校验用户是否已注册企业")
    @GetMapping("/check/checkLoginCompanyByUserId/{userId}")
    public R checkLoginCompanyByUserId(@PathVariable Long userId){
        boolean status = merchantService.checkLoginCompany(userId);
        return R.ok(status);
    }

//    @ApiOperation("创建企业组织")
//    @PostMapping("/create/company")
    public R createCompanyMessage(@RequestBody CreateCompanyMessageRq rq){
        boolean status = merchantService.createCompanyMessage(rq);
        return R.ok(status);
    }

    @PostMapping("/addMerChant")
    @ApiOperation("商家入驻申请")
    public R addMerChant(@RequestBody Merchant merchant){
        return R.ok(merchantService.addMerChant(merchant));
    }
    @ApiOperation("商家入驻审核")
    @PostMapping("merchantCheck")
    public R merchantCheck(@RequestBody CheckVo checkVo){
        return R.ok(merchantService.merchantCheck(checkVo));
    }

    @ApiOperation("上传文件")
    @PostMapping("/upload/companyFile")
    public R uploadCompanyFile(@RequestParam("file") MultipartFile file){
        String url = merchantService.uploadCompanyFile(file);
        return R.ok(url);
    }
    

    @PostMapping("/page")
    @ApiOperation(value = "商家入驻信息分页")
    public R<Page<Merchant>> pageList(@RequestBody MerchantPagePo merchantPagePo){
        return R.ok(merchantService.pageList(merchantPagePo));
    }

    @ApiOperation("商家个人信息详情")
    @GetMapping("/detail")
    public R<Merchant> detail(){
        return R.ok(merchantService.detail());
    }

    @ApiOperation("商家个人信息详情")
    @GetMapping("/detail/{id}")
    public R<Merchant> detailById(@PathVariable Long id){
        return R.ok(merchantService.detailById(id));
    }

    @ApiOperation(("商家数据信息维护数据统计"))
    @GetMapping("statistics")
    public R<LinkedList<MerchantStatisticVo>> statistics(){
        return R.ok(merchantService.statistics());
    }


    @PostMapping("/updateMerchant")
    @ApiOperation(value = "商家信息修改")
    public R updateMerchant(@RequestBody Merchant merchant){
        return R.ok(merchantService.updateMerchant(merchant));
    }


    @GetMapping("/updateGoodsView/{goodsViewId}")
    @ApiOperation(value = "修改商品浏览记录")
    public R updateGoodsView(@PathVariable Long goodsViewId){
        return R.ok(merchantService.updateGoodsView(goodsViewId));
    }


    @PostMapping("/merchantOverview")
    @ApiOperation(value = "商家收支管理-支付金额排行")
    public R<OrderRankMerchantVo> merchantOverview(@RequestBody IncomePo incomePo){
        return R.ok(merchantService.merchantOverview(incomePo));
    }
    @PostMapping("/realTimeOverview")
    @ApiOperation(value = "商家收支管理-实时概况")
    public R<RealTimeVo> realTimeOverview(@RequestBody IncomePo incomePo){
        return R.ok(merchantService.realTimeOverview(incomePo));
    }
    @PostMapping("/flowOverview")
    @ApiOperation(value = "商家收支管理-浏量看板")
    public R<FlowTimeVo> flowOverview(@RequestBody IncomePo incomePo){
        return R.ok(merchantService.flowOverview(incomePo));
    }
    @PostMapping("/allOverview")
    @ApiOperation(value = "商家收支管理-整体看板")
    public R<AllTineVo> allOverview(@RequestBody IncomePo incomePo){
        return R.ok(merchantService.allOverview(incomePo));
    }

    @PostMapping("/microgrid/sale")
    @ApiOperation(value = "微电网--销售额统计")
    public R<MicrogridVo> microgridSale(@RequestBody MicrogridPo microgridPo){
        return R.ok(merchantService.microgridSale(microgridPo));
    }

    @PostMapping("/microgrid/saleType")
    @ApiOperation(value = "微电网--销售额分类")
    public R<List<MicrogridSale>> microgridSaleType(@RequestBody MicrogridPo microgridPo){
        return R.ok(merchantService.microgridSaleType(microgridPo));
    }

    @PostMapping("/microgrid/workOrder")
    @ApiOperation(value = "微电网--运维统计")
    public R<MicrogridVo> microgridWorkOrder(@RequestBody MicrogridOrderPo microgridOrderPo){
        return R.ok(merchantService.microgridWorkOrder(microgridOrderPo));
    }

    @ApiOperation("微电网--总销量、总销售额")
    @PostMapping("/microgrid/itemStatistics")
    public R<ItemStatisticsVo> itemStatistics(@RequestBody ItemStatisticsPo itemStatisticsPo){
        return R.ok(merchantService.itemStatistics(itemStatisticsPo));
    }

    @ApiOperation("微电网--订单总览")
    @PostMapping("/microgrid/orderOverview")
    public R<List<OrderOverviewVo>> orderOverview(@RequestBody MicrogridPo microgridPo){
        return R.ok(merchantService.orderOverview(microgridPo));
    }
    @GetMapping("/merchantUserList")
    @ApiOperation(value = "商家用户下拉")
    public R<List<SysUser>> merchantUserList(){
        return R.ok(merchantService.merchantUserList());
    }
}
